var util = require('../../../utils/util.js')
var _this
Page({
  data:{
    tel:'',
    btnEnable:false,
    btnStyle: 'disabled'
  },
  bindinput: function(e) {
    var content = e.detail.value
    if (_this.tel_str(content)) {
      _this.setData({
        btnEnable:true,
        btnStyle:'enabled',
        tel: content
      })
    }else{
      _this.setData({
        btnEnable: false,
        btnStyle: 'disabled'

      })
    }
  },
  goContinue: function() {
    if (!_this.data.btnEnable){
      wx.showToast({
        title: '请输入正确的手机号码',
        icon:'none'
      })
      return
    }
    _this.handleUpdate()
    wx.navigateTo({
      url: '../../modules/peopleAssigned/infoGender/infoGender'
    })
  },
  onLoad: function(){
    _this = this
  },
  tel_str: function (t) {
    var matched = false
    if (t && (t = t.trim()), t) {
      if (/^((1[3,5,8][0-9])|(14[5,7])|(17[0,6,7,8]))\d{8}$/.test(t)) matched = true;
    } 
    return matched
  },
  handleUpdate: () => {
    var data = {'telPhone':_this.data.tel}
    util.updateUserInfo(_this.requestDidResponse, _this.requestDidFaild,data)
  },
  requestDidResponse: (res) => {
    console.log('did receive response: ' + res)
    if (res.status == '200') {
    }
  },
  requestDidFaild: (res) => {

  }
})